package com.youhong.teethcare.history;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.youhong.teethcare.R;
import com.youhong.teethcare.javabeans.BrushingRecord;
import com.youhong.teethcare.adapter.MyPagerAdapter;
import com.youhong.teethcare.utils.DBHelper;

import java.util.Calendar;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class RealtimeDataFragment extends Fragment {

    public RealtimeDataFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_realtime_data, container, false);
        getViews(v);
        return v;
    }


    public void setDate(Calendar calendar) {

        c = calendar;
        if (vp != null) {
            renderData();
        }

    }

    Calendar c;
    ViewPager vp;
    MyPagerAdapter adapter = null;

    private void getViews(View view) {

        vp = view.findViewById(R.id.frag_realtimeData_vp);
        c = Calendar.getInstance();
        renderData();
    }

    private void renderData() {

        List<BrushingRecord> list =
                DBHelper.getDbHelper(getContext()).queryBrushRecordByDay(c,BrushingRecord.ALL_DATA);

        adapter = new MyPagerAdapter(getContext(), list);
        vp.setAdapter(adapter);

    }
}